<template>
	<view style="position: fixed; width: 100%; height: 100%;justify-content: center;align-items: center;">
		<avatar 
		style="display: flex;justify-content: center;align-items: center;"
			:bgImage="imgBg"
			selWidth="200px" selHeight="200px"  ref='avatar' fileType='png'
			:avatarSrc="url" @upload="myUpload" quality="1" inner=true
			avatarStyle="width: 200px; height: 200px; margin: 40px;">
		</avatar>
		<button type="button" id="submitBtn" @click="clk" class="yes"
			style="background-color: #61ac85;border: 1px solid #579572;">修改</button>
		<!-- <button @click="clk" class="lanch" style="background-color: #61ac85;border: 1px solid #579572;height: 50px;display: flex;justify-content: center;align-items: center;">选择头像</button> -->
	</view>
</template>

<script>
	import avatar from "../../../components/yq-avatar/yq-avatar.vue";
	import config from '@/config'
	export default {
		data() {
			return {
				urls: [],
				url:"../https://yo.docshare.org.cn/static/logo.png",
				imgBg: "../https://yo.docshare.org.cn/static/a.jpg",
				info: {},
			}
		},
		onLoad(option) {
			if(option.url){
				this.url = option.url;
			}
			if(option.id){
				this.id = option.id;
			}
			uni.request({
				url: `${config.baseUrl}/my/info?token=`+uni.getStorageSync('token'),
				method: 'POST',
				success(r) {
					if (r.data.succ) {						
						that.info = r.data.data;
						that.url = getImgUrl(that.info.photo);
						console.log(r.data);
					} else {
						
					}
				}
			})
		},
		methods: {
			getImgUrl:function(image){//获取图片，图片地址拼接函数
					return `${config.baseUrl}`+image;
				},
			clk() {
				let avatar = this.$refs.avatar;
				avatar.fChooseImg(1, {selWidth: "480upx", selHeight: "480upx", expWidth: "480px", expHeight: "480upx", inner:false}, {data: 'xxx'});
			},
			myUpload(rsp) {
				console.log(rsp);
				this.url = rsp.path;
				//rsp.avatar.imgSrc = rsp.path;
				debugger
				uni.uploadFile({
					url: `${config.baseUrl}` + '/upp?token='+uni.getStorageSync('token'),
					filePath: rsp.path,
					name: 'photo',
					formData: {
						'avatar': rsp.path,
						'token':uni.getStorageSync('token')
					},
					success: (uploadFileRes) => {
						debugger
						console.log(uploadFileRes.data);
					},
					complete(res) {
						debugger
						console.log(res)
					}
				});
				
			}
		},
		components: {
			avatar
		}
	}
</script>

<style>
</style>
